import request from '../utils/request';
import qs from 'qs';
export const fetchData = query => {
    return request({
        url: './table.json',
        method: 'get',
        params: query
    });
};
function getData(params) {
    console.log(params)
    const str = [];
    const num = Object.keys(params);
    num.map((item) => {
        var strItem = `${item}=${params[item]}`
        str.push(strItem);
    })
    let data = str.join('&');
    return data.toString();
}
export const loginData = query => {
    return request({
        url: '/user.php',
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: query
    })
}

export const tableData = query => {
    return request({
        url: '/customer.php',
        method: 'GET',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
export const staffsData = query => {
    return request({
        url:'/staffs.php',
        method:'GET',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
export const submitCustomerEdit = query => {
    return request({
        url: '/customerEdit.php',
        method: 'POST',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: getData(query)
    })
}

export const addCustomer = query => {
    return request({
        url: '/customerAdd.php',
        method: 'POST',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: getData(query)
    })
}
export const delCustomer = query => {
    return request({
        url: '/customerDel.php',
        method: 'POST',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: getData(query)
    })
}

export const getGoods = query =>{
    return request({
        url: '/getGoods.php',
        method: 'GET',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
export const submitGoodsEdit = query => {
    return request({
        url: '/goodsEdit.php',
        method: 'POST',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: getData(query)
    })
}
export const submitGoodsDel = query => {
    return request({
        url: '/goodsDel.php',
        method: 'POST',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: getData(query)
    })
}
// 获取评价
export const getDiscuss = query => {
    return request({
        url: '/discuss.php',
        method: 'GET',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    })
}
//获取用户信息
export const getUser = query => {
    return request({
        url: '/getUser.php',
        method: 'GET',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    })
}
// 用户登录
export const userLogin = query => {
    return request({
        url: '/userLogin.php',
        method: 'POST',
        header: { 'Content-Type': 'application/x-www-form-urlencoded' },
        data: getData(query)
    })
}